package icu.qx.diagram.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.common.security.utils.SecurityUtils;
import icu.qx.diagram.domain.Drawback;
import icu.qx.diagram.domain.MaterialInbound;
import icu.qx.diagram.service.IMaterialInboundService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/diagram/materialInbound")
public class MaterialInboundController extends BaseController {
    private final IMaterialInboundService iMaterialInboundService;
    @Autowired
    public MaterialInboundController(IMaterialInboundService iMaterialInboundService)
    {
        this.iMaterialInboundService=iMaterialInboundService;
    }
    @RequiresPermissions("diagram:materialInbound:list")
    @GetMapping("/list")
    public TableDataInfo list(MaterialInbound materialInbound)
    {
        startPage();
        List<MaterialInbound> list=iMaterialInboundService.selectMaterialInboundList(materialInbound);
        for(MaterialInbound m:list){
            m.setCreatorName(SecurityUtils.getUsername());
        }
        return getDataTable(list);
    }
    /**
     * 导出来料统计
     */
    @RequiresPermissions("diagram:materialInbound:export")
    @Log(title = "来料统计", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MaterialInbound materialInbound) {
        List<MaterialInbound> list = iMaterialInboundService.selectMaterialInboundList(materialInbound);
        ExcelUtil<MaterialInbound> util = new ExcelUtil<>(MaterialInbound.class);
        util.exportExcel(response, list, "来料统计数据");
    }
}
